/**
 * this page is an ajax page for index.html
 */
$(document).ready(function () {
	$.ajax({
		url: '../examieeAll.action',    
		type: 'post',    
		cache: false,    
		dataType: 'json',   
		data: {}, 
		success: function (resp) {
			var result = eval("("+resp+")");
			//alert(result);
			var array1 = eval("("+result.data+")");
			var html = "";
    		if( result.flag == "true" ){  
    			//alert("加载成功");
    			$.each(array1, function(i, value) {
    				html += "<tr><td>"+value.admitId+"</td><td>"+value.userName+"</td><td>"+value.gender+"</td><td>"+value.phoneNum+"</td><td>"+value.subject+"</td><td id=\""+ value.admitId +"\">";
    				if(value.tempExamId != ""&&value.tempExamId != null){
    					html += value.tempExamId + "</td></tr>"
    				}else{
    					html += "<button type=\"button\" class=\"btn btn-primary margin-right\" onclick=\"confirm("+ value.admitId +")\">确认</button></td></tr>"
    				}
    			});
    			//alert(html);
    			$("#data").html(html);
            }else{  
             	alert(result.reason);    
            }    
		},    
		error : function () {   
     	 	alert("通信失败");    
		}    
	})
	
	$("#searchBtn").click(function (){
		$.ajax({
			url: '../examieeSearch.action',    
    		type: 'post',    
    		cache: false,    
    		dataType: 'json',   
    		data: {admitID:$.toJSON({admitId:$('#searchText').val()})}, 
    		success: function (resp) {
    			var result = eval("("+resp+")");
    			var html = "";
        		if( result.flag == "true" ){  
        		//	alert("加载成功");
    				html += "<tr><td>"+result.admitId+"</td><td>"+result.userName+"</td><td>"+result.gender+"</td><td>"+result.phoneNum+"</td><td>"+result.subject+"</td><td id=\""+ result.admitId +"\">";
    				if(result.tempExamId != ""){
    					html += result.tempExamId + "</td></tr>"
    				}else{
    					html += "<button type=\"button\" class=\"btn btn-primary margin-right\" onclick=\"confirm("+ result.admitId +")\">确认</button></td></tr>"
    				}
        		//  alert(html);
        			$("#data").html(html);
                }else{  
                 	alert(result.reason);    
                }    
    		},    
    		error : function () {   
         	 	alert("通信失败");    
    		}    
		})
	});
})

function confirm(admintId){
	$.ajax({
		url: '../confirm.action',    
		type: 'post',    
		cache: false,    
		dataType: 'json',   
		data: {admitID:$.toJSON({admitId:admintId})}, 
		success: function (resp) {
			var result = eval("("+resp+")");
			//alert(result);
			var html = "";
    		if( result.flag == "true" ){  
    		//	alert("加载成功");
    			html += result.tempExamId
    			alert(html);
    			$("#"+admintId).html("");
    			$("#"+admintId).text(html)
            }else{  
             	alert(result.reason);    
            }    
		},    
		error : function () {   
     	 	alert("通信失败");    
		}    
	})
}


